package game.controller;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


/**
 * 监听者，继承KeyListener接口，负责监听用户的键盘输入，并将监听结果告知指定的 Controller，
 *
 * @author 陈渤林
 */
public class Listener implements KeyListener {

    /**
     * 指定的 Controller
     */
    private Controller controller;

    /**
     * 构造函数，需要传入指定的 Controller
     *
     * @param controller 指定的 Controller
     */
    Listener(Controller controller) {
        this.controller = controller;
    }

    @Override
    public void keyPressed(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_ESCAPE:
                this.controller.dispose();
                break;
            case KeyEvent.VK_SPACE:
                this.controller.createBlocks();
                break;
            case KeyEvent.VK_R:
                this.controller.init();
                break;
            case KeyEvent.VK_LEFT:
            case KeyEvent.VK_A:
                this.controller.moveBlocks(Direction.LEFT);
                this.controller.createBlocks();
                break;
            case KeyEvent.VK_D:
            case KeyEvent.VK_RIGHT:
                this.controller.moveBlocks(Direction.RIGHT);
                this.controller.createBlocks();
                break;
            case KeyEvent.VK_W:
            case KeyEvent.VK_UP:
                this.controller.moveBlocks(Direction.UP);
                this.controller.createBlocks();
                break;
            case KeyEvent.VK_S:
            case KeyEvent.VK_DOWN:
                this.controller.moveBlocks(Direction.DOWN);
                this.controller.createBlocks();
                break;
//		case KeyEvent.VK_Q:
//			this.controller_.rotateBoard90Degree();
            default:
                break;
        }
//		repaint();
    }

    @Override
    public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void keyTyped(KeyEvent e) {
        // TODO Auto-generated method stub

    }

}
